# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@io_bazel_rules_docker//cc:image.bzl", "cc_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bazel:pl_build_system.bzl", "pl_cc_binary")

package(default_visibility = ["//src/stirling:__subpackages__"])

container_image(
    name = "stirling_binary_base_image",
    base = "//:pl_cc_base_debug_image",
    layers = ["//src/stirling:bpf_layer"],
)

pl_cc_binary(
    name = "stirling_wrapper",
    srcs = ["stirling_wrapper.cc"],
    defines = [
        "PXL_SUPPORT",
    ],
    deps = [
        "//src/carnot/planner/probes:tracepoint_generator_lib",
        "//src/common/signal:cc_library",
        "//src/shared/tracepoint_translation:cc_library",
        "//src/stirling:cc_library",
    ],
)

# A version of stirling_wrapper without the compiler.
# Used in //src/stirling/e2e_tests:stirling_wrapper_size_test
pl_cc_binary(
    name = "stirling_wrapper_core",
    srcs = ["stirling_wrapper.cc"],
    deps = [
        "//src/common/signal:cc_library",
        "//src/stirling:cc_library",
    ],
)

cc_image(
    name = "stirling_wrapper_image",
    base = ":stirling_binary_base_image",
    binary = ":stirling_wrapper",
)

container_push(
    name = "push_stirling_wrapper_image",
    format = "Docker",
    image = ":stirling_wrapper_image",
    registry = "gcr.io",
    repository = "pl-dev-infra/stirling_wrapper",
    tag = "{BUILD_USER}",
    tags = ["manual"],
)

pl_cc_binary(
    name = "stirling_dt",
    srcs = ["stirling_dt.cc"],
    deps = [
        "//src/stirling:cc_library",
    ],
)

pl_cc_binary(
    name = "go_binary_parse_profiling",
    srcs = ["go_binary_parse_profiling.cc"],
    deps = [
        "//src/stirling:cc_library",
    ],
)

cc_image(
    name = "stirling_dt_image",
    base = ":stirling_binary_base_image",
    binary = ":stirling_dt",
)

container_push(
    name = "push_stirling_dt_image",
    format = "Docker",
    image = ":stirling_dt_image",
    registry = "gcr.io",
    repository = "pl-dev-infra/stirling_dt",
    tag = "{BUILD_USER}",
    tags = ["manual"],
)

pl_cc_binary(
    name = "stirling_profiler",
    srcs = ["stirling_profiler.cc"],
    deps = [
        "//src/shared/pprof:cc_library",
        "//src/stirling/source_connectors/perf_profiler:cc_library",
    ],
)

cc_image(
    name = "stirling_profiler_image",
    base = ":stirling_binary_base_image",
    binary = ":stirling_profiler",
)

container_push(
    name = "push_stirling_profiler_image",
    format = "Docker",
    image = ":stirling_profiler_image",
    registry = "gcr.io",
    repository = "pl-dev-infra/stirling_profiler",
    tag = "{BUILD_USER}",
    tags = ["manual"],
)

cc_binary(
    name = "stirling_ctrl",
    srcs = ["stirling_ctrl.c"],
    visibility = [
        "//:__pkg__",
        "//src/stirling:__subpackages__",
    ],
)
